
// 数据库操作

let query = require("./mysql")

/**
 * 数据库操作可以通过 ORM工具操作
 * Sequelize-Automate: 自动生成 Sequelize Models
 * sequelize-auto  数据库 转 model
 *
*/
module.exports = {
    /**
     * 判断登录
     * @param {array} data
     */
    islogin:async function(data){
        let sql = 'select * from user where userName = ? and pwd = ?'

        try{
            let result = await query(sql,data)
            if(result.length>0){
                return result;
            }else{
                return false;
            }
        }
        catch (e) {
            return false;
        }
    },
    allUsers:async function(data){
        let sql = 'select userName from user'

        try{
            let result = await query(sql,data)
            if(result.length>0){
                return result;
            }else{
                return false;
            }
        }
        catch (e) {
            return false;
        }
    },
    register:async function(data){
        let sql = 'insert into user(userName,pwd,registerTime) values(?,?,?)'
        // console.log("sql data" + data);
        try{
            let result = await query(sql,data)
            console.log("query result:"+result);
            if(result){
                return true;
            }else{
                return false;
            }
        }
        catch (e) {
            return false;
        }
    },
}
